/*
 * HttpMessage.h
 *
 *  Created on: 2018年7月3日
 *      Author: zhengboyuan
 */

#ifndef HttpMessage_H_
#define HttpMessage_H_

#include "BasicType.h"
#include <string>
#include <map>
#include <stdint.h>


struct CaseKeyCmp
{
    bool operator() (const std::string& p1, const std::string& p2) const
    {
        return strcmp(p1.c_str(), p2.c_str()) < 0;
    }
};

typedef std::map<std::string, std::string> Headers_t;
typedef std::map<std::string, std::string> Params_t;


class HttpMessage
{
public:
    HttpMessage();
    virtual ~HttpMessage();

    std::string  m_line;
    Headers_t    m_header;
    std::string  m_body;


    std::string  m_version;

    std::string  m_method;
    std::string  m_url;
    std::string  m_urlPath;

    int     m_status;
    std::string  m_reason;


    int32_t getContentLength() const;

    bool getContentType(std::string& name) const;

    void clear();

    bool isRequest() const;
    bool isResponse() const;

    // request
    const std::string& getUrl() const;

    const std::string& getUrlPath() const;

    const std::string& getMethod() const;

    int getStatus() const;
    const std::string& getReason() const;

    bool getHeader(const std::string& name, std::string& value) const;

    bool hasHeader(const std::string& name) const;

    bool igetHeader(const std::string& name, std::string& value) const;

    bool ihasHeader(const std::string& name) const;

private:
    Headers_t::const_iterator ifindHeader(const std::string& name) const;

private:


};


#endif /* HttpMessage_H_ */
